<?php
	header("Content-Type: text/html;charset=utf-8");
	include("../_judge.php");
	include("../../function/function.php");
	
	$action = chkstr(trim($_REQUEST['action']));
	$bigclass_cn = chkstr(trim($_REQUEST['bigclass_cn']));
	$bigclass_en = chkstr(trim($_REQUEST['bigclass_en']));
	$bigclass_text = chkstr(trim($_REQUEST['bigclass_text']));
	$bigclass_order = chkstr(trim($_REQUEST['bigclass_order']));
	$pid = chkstr(trim($_REQUEST['pid']));
	$bigclass_menu = chkstr(trim($_REQUEST['bigclass_menu']));
	$bigclass_urls = chkstr(trim($_REQUEST['bigclass_urls']));
	$bigclass_style = chkstr(trim($_REQUEST['bigclass_style']));
	$bigclass_pic = chkstr(trim($_REQUEST['bigclass_pic']));
	$id = chkstr(trim($_REQUEST['id']));

	if($action == "addbigclass"){

		$mysql = new sqlstr("kboy_bigclass"); 
		$mysql -> set("pid",0,true);
		$mysql -> set("bigclass_style",3,true);
		$news_sql = $mysql -> insertSql();
		$news_res = mysql_query($news_sql);
		if($news_res){
			$last_id = mysql_insert_id();
			mysql_query("update kboy_bigclass set bigclass_order=$last_id where id=$last_id");
			echo re("newsmanage.php#Anchor".$$last_id);
		}else{
			echo erro("服务器内部错误");
		}
	
	}elseif($action == "add"){
		if(strlen($id)<1){
			echo erro("ID不能为空");
		}
		if(!is_numeric($id)){
			echo erro("ID错误");
		}
		if(getNewsNums("kboy_bigclass","id=$id")<1){
			echo erro("至少选择一条信息");
		}
	
		$mysql = new sqlstr("kboy_bigclass"); 
		$mysql -> set("pid",$id,true);
		$mysql -> set("bigclass_style",3,true);
		$news_sql = $mysql -> insertSql();
		$news_res = mysql_query($news_sql);
		if($news_res){
			$last_id = mysql_insert_id();
			mysql_query("update kboy_bigclass set bigclass_order=$last_id where id=$last_id");
			echo re("newsmanage.php#Anchor".$last_id);
		}else{
			echo erro("服务器内部错误");
		}
	}elseif($action == "edit"){
		if(strlen($id)<1){
			echo erro("ID不能为空");
		}
		if(!is_numeric($id)){
			echo erro("ID错误");
		}
		if(getNewsNums("kboy_bigclass","id=$id")<1){
			echo erro("至少选择一条信息");
		}

		$mysql = new sqlstr("kboy_bigclass"); 
		$mysql -> set("bigclass_cn",$bigclass_cn);
		$mysql -> set("bigclass_en",$bigclass_en);
		$mysql -> set("bigclass_order",$bigclass_order,true);
		$mysql -> set("bigclass_menu",$bigclass_menu);
		$mysql -> set("bigclass_urls",$bigclass_urls);
		$mysql -> set("bigclass_style",$bigclass_style,true);
		$mysql -> set("bigclass_pic",$bigclass_pic);
		$mysql -> set("bigclass_text",$bigclass_text);
		$mysql -> set("pid",$pid,true);
		$news_sql = $mysql -> updateSql("id=$id");
		$news_res = mysql_query($news_sql);
		if($news_res){
			echo re("newsmanage.php#Anchor".$id);
		}else{
			echo erro("服务器内部错误");
		}
		
	}elseif($action == "del"){
		if(strlen($id)<1){
			echo erro("ID不能为空");
		}
		if(!is_numeric($id)){
			echo erro("ID错误");
		}
		if(getNewsNums("kboy_bigclass","id=$id")<1){
			echo erro("至少选择一条信息");
		}
		if($id >0 && $id<=4){
			echo erro("主分类不可删除");
		}
		$getSoonID = "";
		getSoonID($id,''); // 获取该ID下的所有子ID
		$mysql = new sqlstr("kboy_bigclass"); 
		$news_sql = $mysql -> deleteSql("id in (".$id.$getSoonID.")");
		$news_res = mysql_query($news_sql);
		if($news_res){
			echo re("newsmanage.php");
		}else{
			echo erro("服务器内部错误");
		}
	}else{
		echo erro("参数错误");
	}
	
?>
